package com.music.note_android.di

import android.content.Context
import androidx.room.Room
import com.music.note_android.data.database.NoteDatabase
import com.music.note_android.data.database.dao.NoteDao
import com.music.note_android.data.database.dao.FolderDao
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object DatabaseModule {
    
    @Provides
    @Singleton
    fun provideNoteDatabase(
        @ApplicationContext context: Context
    ): NoteDatabase {
        return Room.databaseBuilder(
            context,
            NoteDatabase::class.java,
            "note_database"
        )
            .fallbackToDestructiveMigration() // 开发阶段允许破坏性迁移
            .build()
    }
    
    @Provides
    fun provideNoteDao(database: NoteDatabase): NoteDao {
        return database.noteDao()
    }
    
    @Provides
    fun provideFolderDao(database: NoteDatabase): FolderDao {
        return database.folderDao()
    }
}